<?php
/***************************************************************************
 *   Copyright (C) 2008 by Julian Cromarty and Stuart Duff (BPX-Dev)       *
 *   julian.cromarty@gmail.com or stu@broken-paradox.com                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/**
*
* A class to dynamically generate the layout of a page
*
*@author Julian Cromarty, Stuart
*/
class layout	{

/**
*
* Generates the header
*
*/
function header()	{
	echo 
	
	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
	
	<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
	
	<head>
	
	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
	
	<meta name=\"description\" content=\"\" />
	
	<meta name=\"keywords\" content=\"\" />
	
	<meta http-equiv=\"keywords\" content=\"\" />
	
	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
	
	<meta name=\"GOOGLEBOT\" content=\"ARCHIVE\" />
	
	<meta name=\"robots\" content=\"Index, Follow\" />
	
	<meta name=\"revisit-after\" content=\"7 Days\" />
	
	<meta name=\"language\" content=\"English\" />
	
	<meta name=\"distribution\" content=\"Global\" />
	
	<meta name=\"rating\" content=\"General\" />
	
	<meta name=\"author\" content=\"bpx\" />
	
	<meta name=\"copyright\" content=\"BPX-Dev\" />
	
	<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\"/>
	
	<title>EHWOTAY!</title>
	</head>
	
	<body>
	
	<div><br/><br/></div>
	
	<div class=\"wrapper\">";
	
	/*
	 * Header php include.
	 */
	
	echo "
	
	<div class=\"header\">
	
	
	<img src=\"img/title.png\" />
	
	
	</div>";
}

/**
*
* Generates the nav bar
*
*/
function nav()	{
	echo"
	
	<div class=\"mainnav\">
			
	<a href=\"index.php\">Home</a><br/>
	
	<h2>Latest Posts<h2>
	
	<ul>
	<li><a href=\"\">News Item</a></li>
	<li><a href=\"\">News Item</a></li>
	<li><a href=\"\">News Item</a></li>
	</ul>
	
	<hr/>
	
	<br/>
	
	<h2>Categories<h2>
	
	<ul>
	<li><a href=\"\">Category</a></li>
	<li><a href=\"\">Category</a></li>
	<li><a href=\"\">Category</a></li>
	</ul>
	
	<hr/>
	
	<br/>\n";
	if (!isset($_SESSION['username']) || (strcmp($_SESSION['username'], "") == 0))	{
		echo "<p>\nWelcome guest\n</p>\n
		<h2>Options<h2>\n
		<ul>
		<li><a href=\"login.php\">Login</a></li>
		<li><a href=\"register.php\">Register</a></li>
		</ul>";
	}
	else	{
		echo "<p>\nWelcome {$_SESSION['username']}\n</p>\n
		<h2>Options<h2>\n
		<ul>
		<li><a href=\"logout.php\">Logout</a></li>
		</ul>";
	}
	echo "<hr/>
	
	<br/>
	
	<h2>Disclaimer<h2>
	
	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc id magna. Nullam ac erat. Morbi mattis. Praesent 
	elementum posuere neque. Sed tortor orci, commodo quis, congue sed, accumsan non, nisl.</p>
	
	<hr/>
	
	
	</div>
	";
}

/**
*
* A post to go in the main section
*
*@param $postData An array containing the data for the post
*/
function post($postData)	{
echo "

<div class=\"post\">

<div class=\"post_content\">

<h2>";
echo $postData['pTitle'];
echo "</h2>

<p>";
echo $postData['pContent'];
echo "</p>
<div class=\"post_author\">";
echo "<p>Written by " . $postData['pAuthor'] . " - " . $postData['pTime'] . "</p>\n";
echo "<p>Tags - ";
foreach ($postData['pTags'] as $tag)	{
	echo $tag . " ";
}
echo "</p>\n

</div> <!-- author -->

</div> <!-- post_content -->

<div class=\"post_menu\">

<hr/>

<a href=\"\">Comment</a> | ";
if ($postData['numComments'] <= 0)	{
	echo "<span class=\"no_comments\">0 Comments</span>";
}
else if ($postData['numComments'] == 1) {
	echo "<a href=\"post.php?id={$postData['pId']}\">1 Comment</a>";
}
else {
	echo "<a href=\"post.php?id={$postData['pId']}\">{$postData['numComments']} Comments</a>";
}
echo	" | <a href=\"\">Edit</a> | <a href=\"\">Send To a Friend</a>

</div>	<!-- post_menu-->

<div class=\"spacer\"><br/><br/></div>
<div class=\"spacer\"><br/><br/></div>

</div> <!-- post -->
";
}

/**
*
* A detailed post with comments to be displayed on its own
*
*@param $postData An array containing the data for the post
*/
function postDetailed($postData)	{
	echo "

			<div class=\"post\">

			<div class=\"post_content\">

			<h2>";
	echo $postData['pTitle'];
	echo "</h2>

			<p>";
	echo $postData['pContent'];
	echo "</p>
			<div class=\"post_author\">";
	echo "<p>Written by " . $postData['pAuthor'] . " - " . $postData['pTime'] . "</p>\n";
	echo "<p>Tags - ";
	foreach ($postData['pTags'] as $tag)	{
		echo $tag . " ";
	}
	echo "</p>\n

			</div> <!-- author -->

			</div> <!-- post_content -->

			<div class=\"post_menu\">

			<hr/>

			<a href=\"\">Comment</a> | <a href=\"\">Edit</a> | <a href=\"\">Send To a Friend</a>

			</div>	<!-- post_menu-->

			<div class=\"spacer\"><br/><br/></div>
			";
	
	if ($postData['numComments'] > 0)	{
		layout::layoutComments($postData['comments']);
	}
	echo "
			</div> <!-- post -->
			";
}

/**
*
* Displays the comments for a post
*
*@param $pId The ID of the post
*/
private function layoutComments($comments)	{
	echo "
			<div class=\"comments\">
			<h2>
			Comments
			</h2>
			<hr/>
			";
	foreach ($comments as $comment)	{
		echo "<h3>\n", $comment['cTitle'], "\n</h3>\n";
		echo "<p>\n", $comment['comment'], "\n</p>\n";
		echo "<p>\nComment written by ", $comment['cAuthor'], "\n</p>\n";
		echo "<hr/>\n";
	}
	echo "</div> <!-- comments -->\n<br/><br/>";
}

/**
*
* Generates the beginning of the main section
*
*/
function beginMain()	{
	echo"
<div class=\"main_index\">

";
}

/**
*
* The end of the main section
*
*/
function endMain()	{
echo
"
<div class=\"low_nav\"><a href=\"\">Back</a> | <a href=\"\">Next</a></div>

</div>

";
}

/**
*
* Generates the footer
*
*/
function footer()	{
/* 
 * This is the footer page, all copyright info goes here.
 * Change the CSS and XHTML validation addresses accroding to your domain location.
 */

echo

"<div class=\"footer\">

<br/>

<h4>&copy; 2008, Broken-Paradox (BPX-Dev) & Urioxis, All rights reserved. 
<a class=\"external\" href=\"\">XHTML</a> and 
<a class=\"external\" href=\"\">
CSS</a> Strict</h4>


</div>

</div>";
}

}
?>